<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
    <script>
        window.onload=function(){
            var canvas=document.getElementById("canvas");
            var cx=canvas.getContext("2d");
            var g=cx.createLinearGradient(0,0,300,300);
            g.addColorStop(0,"lightblue");
            g.addColorStop(0.5,"yellow");
            g.addColorStop(1,"tomato");
           
            cx.fillStyle=g;
            for(var i=1;i<300;i += 30){
                drawCircle(i,i,i/2)
            }
            // 封装绘制圆形的函数
            function drawCircle(x,y,radius){
                // 开始路径
                cx.beginPath();
                // 设置路径
                cx.arc(x,y, radius,0, Math.PI*2);
                // 结束路径
                cx.closePath();

                // 填充路径,绘制图形
                cx.fill();
            }
          

        }




    </script>
</head>
<body>
    <canvas id="canvas" width="600px" height="600px" style="background-color:#ccc"></canvas>
    
</body>
</html>